#include "stdafx.h"
#include "Helper.h"


std::wstring& EscapXml(std::wstring& src)
{
	int nLength = src.length();
	int nCnt;
	wchar_t ch;
	for(int i = 0,nCnt = 0 ; i < nLength ; i++ )
	{
		ch = src[nCnt];
		switch(ch)
		{
			case L'<':
				src.replace(nCnt,1,L"&lt;");
				nCnt += 4;
				break;
			case L'>':
				src.replace(nCnt,1,L"&gt;");
				nCnt += 4;
				break;
			case L'&':
				src.replace(nCnt,1,L"&amp;");
				nCnt += 5;
				break;
			case L'\'':
				src.replace(nCnt,1,L"&apos;");
				nCnt += 6;
				break;
			case L'"':
				src.replace(nCnt,1,L"&quot;");
				nCnt += 6;
				break;
			default:
				nCnt++;
				break;
		}
		
	}
	return src;
}
